/*
 * Created by SharpDevelop.
 * User: Adam
 * Date: 12/19/2008
 * Time: 10:43 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace Yaml.Library
{
    /// <summary>
    /// Tree class
    /// </summary>
    /// <typeparam name="TLeft">The type of the left.</typeparam>
    /// <typeparam name="TRight">The type of the right.</typeparam>
    public class Pair<TLeft, TRight> : IEquatable<Pair<TLeft, TRight>>
    {
    	private TLeft _left;
    	private TRight _right;
    	
        /// <summary>
        /// Left node.
        /// </summary>
        public TLeft Left {
        	get {
        		return this._left;
        	}
        	set {
        		this._left = value;
        	}
        }
        
        /// <summary>
        /// Right node.
        /// </summary>
        public TRight Right {
        	get {
        		return this._right;
        	}
        	set {
        		this._right = value;
        	}
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Pair&lt;TLeft, TRight&gt;"/> class.
        /// </summary>
        /// <param name="left">The left node.</param>
        /// <param name="right">The right node.</param>
        public Pair(TLeft left, TRight right)
        {
            Left = left;
            Right = right;
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </returns>
        public override string ToString()
        {
            return string.Format("({0},{1})", Left, Right);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. <see cref="M:System.Object.GetHashCode"></see> is suitable for use in hashing algorithms and data structures like a hash table.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"></see>.
        /// </returns>
        public override int GetHashCode()
        {
            return Left.GetHashCode() + Right.GetHashCode();
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"></see> to compare with the current <see cref="T:System.Object"></see>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is Pair<TLeft, TRight>)
            {
                return this.Equals(obj);
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the other parameter; otherwise, false.
        /// </returns>
        public bool Equals(Pair<TLeft, TRight> other)
        {
            return this.Left.Equals(other.Left) && this.Right.Equals(other.Right);
        }

        /// <summary>
        /// Implements the equality operator (==).
        /// </summary>
        /// <param name="one">The left side of the equality test.</param>
        /// <param name="other">The right side of the equality test.</param>
        /// <returns>The result of the equality test.</returns>
        public static bool operator ==(Pair<TLeft, TRight> left, Pair<TLeft, TRight> right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// Implements the inequality operator (!=).
        /// </summary>
        /// <param name="one">The left side of the inequality test.</param>
        /// <param name="other">The right side of the inequality test.</param>
        /// <returns>bool value indicating the status of the inequality.</returns>
        public static bool operator !=(Pair<TLeft, TRight> left, Pair<TLeft, TRight> right)
        {
            return !(left == right);
        }
    }

}
